<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="供货商名称">
                <a-input placeholder="请输入供货商名称" v-model="queryParam.name" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="手机号码">
                <a-input placeholder="请输入供货商电话" v-model="queryParam.tel" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="getList">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false">
      <div class="table-operator" style="display: flex; justify-content: space-between">
        <a-radio-group v-model="queryParam.status" @change="getList">
          <a-radio-button value="-1"> 全部 </a-radio-button>
          <a-radio-button value="0"> 待审核 </a-radio-button>
          <a-radio-button value="1"> 已同意 </a-radio-button>
          <a-radio-button value="2"> 已拒绝 </a-radio-button>
        </a-radio-group>
        <div>
          <a-dropdown>
            <a-menu slot="overlay">
              <a-menu-item @click="allDelete">批量删除</a-menu-item>
            </a-menu>
            <a-button> 批量操作 </a-button>
          </a-dropdown>
        </div>
      </div>
      <a-table
        :rowKey="
          (r, i) => {
            return r.id
          }
        "
        :pagination="{
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :columns="columns"
        :data-source="list"
        :scroll="{ x: 'max-content' }"
      >
        <span slot="name" slot-scope="scope">
          <div class="name">
            <div class="pic">
              <img :src="scope.info.logo" alt="" />
            </div>
            <div class="info">
              <span>{{ scope.name }}</span>
              <span>{{ scope.info.info_name }}</span>
            </div>
          </div>
        </span>
        <span slot="mobile" slot-scope="scope">
          {{ scope.info.info_tel }}
        </span>
        <span slot="cash_type" slot-scope="text">
          {{ text == 1 ? '微信' : text == 2 ? '支付宝' : '银行卡' }}
        </span>
        <div slot="account" slot-scope="scope">
          <div>
            {{ scope.cash_type == 1 ? '微信账号' : scope.cash_type == 2 ? '支付宝' : '银行卡' }}:{{ scope.account }}
          </div>
          <div>
            {{ scope.cash_type == 1 ? '微信昵称' : scope.cash_type == 2 ? '支付宝昵称' : '姓名' }}:{{ scope.name }}
          </div>
          <div v-if="scope.cash_type == 3">银行开户行:{{ scope.bank_name }}</div>
        </div>
        <span slot="status" slot-scope="text">
          {{ text == 0 ? '申请中' : text == 1 ? '已同意' : '已拒绝' }}
        </span>
        <span slot="addtime" slot-scope="text">
          {{ text > 0 ? $moment(text * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' }}
        </span>
        <div slot="action" slot-scope="scope">
          <template v-if="scope.status == 0">
            <a-button type="link" @click="changeStatus(scope, 1)">同意</a-button> |
            <a-button type="link" @click="changeStatus(scope, 2)">拒绝</a-button>
          </template>
          <a-button type="link" v-if="scope.status == 1" disabled>已同意</a-button>
          <a-button type="link" v-if="scope.status == 2" disabled>已拒绝</a-button>
        </div>
        <span slot="service_charge" slot-scope="scope">
          {{ scope.status == 1 ? scope.service_charge : '-' }}
        </span>

        <span slot="type" slot-scope="text">
          {{ text == '0' ? '个人' : text == '1' ? '商户' : '供货商' }}
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { supplierWithdrawList, withdrawStatus } from '@/api/purchase/purchase'
import tabList from '@/views/saas/components/tabList.vue'
import { cyyUploadImg } from '@/components/CyyUi'
const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 80,
  },
  {
    title: '供货商',
    scopedSlots: {
      customRender: 'name',
    },
    width: 280,
  },
  {
    title: '商户类型',
    dataIndex: 'type',
    scopedSlots: {
      customRender: 'type',
    },
  },
  {
    title: '手机号',
    scopedSlots: {
      customRender: 'mobile',
    },
  },
  {
    title: '提现方式',
    dataIndex: 'cash_type',
    scopedSlots: {
      customRender: 'cash_type',
    },
  },
  {
    title: '提现账号',
    scopedSlots: {
      customRender: 'account',
    },
  },
  {
    title: '提现金额',
    dataIndex: 'price',
    sorter: (a, b) => a.price - b.price,
  },
  {
    title: '服务费',
    scopedSlots: {
      customRender: 'service_charge',
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    scopedSlots: {
      customRender: 'status',
    },
  },
  {
    title: '操作',
    scopedSlots: {
      customRender: 'action',
    },
  },
]

export default {
  components: {
    tabList,
    cyyUploadImg,
  },
  data() {
    return {
      tabList: [
        {
          key: 'saasSupplierFinanceWithdraw',
          name: '提现申请',
        },
        {
          key: 'saasPurchaseFinanceRecordList',
          name: '提现记录',
        },
      ],
      // 搜索参数
      queryParam: {
        page: 1,
        limit: 10,
        tel: '',
        name: '',
        could_user_id: '',
        status: '-1',
      },
      selectedRowKeys: [],
      columns,
      list: [],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 关闭弹窗的回调
    closeModal() {},
    // 分页请求
    tablePageChange(e) {
      this.queryParam.page = e
      this.getList()
    },
    // 获取数据
    async getList() {
      const hide = this.$message.loading('加载中...', 1000)
      const res = await supplierWithdrawList(this.queryParam)
      if (res.code == 0) {
        this.list = res.data.list
        this.totalCount = res.data.count
      }
      hide()
    },
    // 点击同意或拒绝
    changeStatus(scope, status) {
      const that = this
      let param = {
        cash_id: scope.id,
        pay_type: scope.cash_type,
        service_charge: 0,
        status,
      }
      let text = status == 1 ? '同意' : '拒绝'
      this.$confirm({
        title: '是否' + text + '申请？',
        onOk() {
          that.withdrawStatus(param)
        },
        onCancel() {},
      })
    },
    // 更改提现状态
    async withdrawStatus(param) {
      const res = await withdrawStatus(param)
      if (res.code == 0) {
        this.getList()
      }
    },
  },
}
</script>
<style lang="less" scoped>
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-right: 20px;
  }
  .select {
    margin-top: 11px;
    display: flex;
    align-items: center;
    margin-right: 15px;
  }
  .ant-btn {
    margin-top: 11px;
  }
}
.tip {
  line-height: normal;
  margin-bottom: 0;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.45);
}

.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
</style>
